<template>
  <div class="crm-dashboard">
    <el-row :gutter="20">
      <!-- 左侧主内容 -->
      <el-col :span="17">
        <!-- 简报统计 -->
        <el-card class="mb-16">
          <div class="brief-report">
            <el-row :gutter="20">
              <el-col :span="4" v-for="item in stats" :key="item.label">
                <div class="brief-item">
                  <el-avatar :size="48" :style="{ background: item.bgColor }">
                    <el-icon :size="28">
                      <component :is="item.icon" />
                    </el-icon>
                  </el-avatar>
                  <div class="brief-info">
                    <div class="brief-num">{{ item.value }}</div>
                    <div class="brief-label">{{ item.label }}</div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 今日行动/邮件跟进 tabs -->
        <el-card class="mb-16">
          <el-tabs v-model="tabActive" type="card">
            <el-tab-pane label="今日行动 (1)" name="action">
              <el-table :data="actions" size="small">
                <el-table-column prop="content" label="行动内容" />
                <el-table-column prop="type" label="行动类型" />
                <el-table-column prop="priority" label="优先级" />
                <el-table-column prop="status" label="状态" />
                <el-table-column prop="planTime" label="计划完成时间" sortable />
                <el-table-column prop="createTime" label="创建时间" sortable />
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="邮件跟进策略 (0)" name="mail" />
          </el-tabs>
        </el-card>

        <!-- 近7天未读邮件/跟进 tabs -->
        <el-card>
          <el-tabs v-model="tabActive2" type="card">
            <el-tab-pane label="近7天未读邮件 (0)" name="mail7">
              <el-table :data="[]" size="small">
                <el-table-column prop="sender" label="发件人" />
                <el-table-column prop="subject" label="主题" />
                <el-table-column prop="time" label="时间" />
              </el-table>
              <div class="empty-data" v-if="true">
                <div style="text-align: center; color: #bfbfbf;">暂无数据</div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="近7天追踪记录 (0)" name="follow7" />
          </el-tabs>
        </el-card>
      </el-col>

      <!-- 右侧侧边栏 -->
      <el-col :span="7">
        <!-- 世界时间 -->
        <el-card class="mb-16">
          <div class="card-header">
            <span>世界时间</span>
            <el-link type="primary" :underline="false" style="float:right;">查看更多</el-link>
          </div>
          <el-table :data="worldTimes" size="small" border style="margin-top: 10px;">
            <el-table-column prop="city" label="" />
            <el-table-column prop="time" label="" />
            <el-table-column label="">
              <template #default="scope">
                <el-link type="primary" :underline="false" size="small">切换城市</el-link>
              </template>
            </el-table-column>
          </el-table>
        </el-card>

        <!-- 实时汇率 -->
        <el-card class="mb-16">
          <div class="card-header">
            <span>实时汇率</span>
            <el-link type="primary" :underline="false" style="float:right;">现汇买入价</el-link>
          </div>
          <div class="exchange-rate">
            <div class="rate-main">
              <span class="rate-num">100</span>
              <span style="font-size: 22px; margin: 0 8px;">≈</span>
              <span class="rate-num rate-right">716.49</span>
            </div>
            <div class="rate-label">
              <el-icon><i-ep-flag /></el-icon> 美元(USD)
              <span style="margin: 0 12px;"></span>
              <el-icon><i-ep-flag /></el-icon> 人民币(CNY)
            </div>
          </div>
        </el-card>

        <!-- 更新日志 -->
        <el-card>
          <div class="card-header">
            <span>更新日志</span>
            <el-link type="primary" :underline="false" style="float:right;">查看更多</el-link>
          </div>
          <el-timeline style="margin-top: 14px;">
            <el-timeline-item v-for="log in logs" :key="log.date" :timestamp="log.date" :type="log.type" placement="top">
              <span>{{ log.content }}</span>
              <el-tag v-if="log.new" type="danger" size="small" style="margin-left: 8px;">新版本</el-tag>
            </el-timeline-item>
          </el-timeline>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from "vue"
import { User, Message, Money, ShoppingCart, UserFilled } from '@element-plus/icons-vue'

const tabActive = ref('action')
const tabActive2 = ref('mail7')

const stats = [
  { label: '邮件发送数', value: 0, icon: Message, bgColor: '#ffae5e' },
  { label: '新录入线索', value: 0, icon: UserFilled, bgColor: '#3acfcf' },
  { label: '跟进客户数', value: 2, icon: User, bgColor: '#6ca7ff' },
  { label: '新销售机会数', value: 0, icon: Money, bgColor: '#ffae5e' },
  { label: '跟进线索数', value: 0, icon: User, bgColor: '#6ca7ff' },
  { label: '新录入客户', value: 2, icon: UserFilled, bgColor: '#3acfcf' },
  { label: '新报价单数', value: 0, icon: Money, bgColor: '#ffae5e' },
  { label: '新订单数', value: 0, icon: ShoppingCart, bgColor: '#fd7e4d' },
]

const actions = [
  {
    content: "221123",
    type: "电话",
    priority: "紧急重要",
    status: "待处理",
    planTime: "2025-07-10 23:59",
    createTime: "2025-07-10 10:19"
  }
]

const worldTimes = [
  { city: "纽约", time: "Wed 23:08" },
  { city: "伦敦", time: "Thu 04:08" },
  { city: "迪拜", time: "Thu 07:08" },
  { city: "东京", time: "Thu 12:08" }
]

const logs = [
  { date: "06-04", content: "兰亚CRM V1.0.0 版本已上线", new: true, type: "primary" },
  { date: "02-18", content: "兰亚CRM V1.0.0 版本已上线", new: false, type: "success" },
  { date: "12-27", content: "兰亚CRM V1.0.0 版本已上线", new: false, type: "info" },
  { date: "10-28", content: "兰亚CRM V1.0.0 版本已上线", new: false, type: "info" },
  { date: "07-29", content: "兰亚CRM V1.0.0 版本已上线", new: false, type: "info" },
]
</script>

<style scoped>
.crm-dashboard {
  background: #f6f8fb;
  min-height: 100vh;
  padding: 20px;
}
.mb-16 { margin-bottom: 16px; }
.card-header {
  font-weight: 500;
  font-size: 15px;
  margin-bottom: 8px;
}
.brief-report {
  padding: 8px 0;
}
.brief-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}
.brief-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.brief-num {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}
.brief-label {
  font-size: 13px;
  color: #888;
}
.exchange-rate {
  padding: 20px 0 6px 0;
  text-align: center;
}
.rate-main {
  font-size: 34px;
  font-weight: bold;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rate-num {
  color: #333;
}
.rate-right {
  color: #ff7c39;
}
.rate-label {
  font-size: 14px;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.empty-data {
  padding: 30px 0;
}
</style>
